-- An example involving defining types and some algorithmic computation

peoplesort is package{

  type person is someone { 
    name has type string;
    spouse has type person;
    spouse default is noone;
  } or noone;
  
  import quick;
  
  peopleComp has type (person,person) =>boolean;
  peopleComp(someone{name=A},someone{name=B}) is A<B;
    
  main has type action();
  main() do {
    people is list{someone{name="peter"}; someone{name="john"; spouse=noone}; someone{name="fred"}; someone{name="fred"};someone{name="andy"}};
    
    logMsg(info,"The list of people is $people");
    logMsg(info,"The sorted list of people is $(quick(people, peopleComp))");
    
    assert inOrder(quick(people,peopleComp),peopleComp);
  }
  
  inOrder(list{},_) is true;
  inOrder(list{X},_) is true;
  inOrder(list{X;Y;..R},C) where not C(Y,X) is inOrder(list{Y;..R},C);
  inOrder(_,_) default is false;
}
